package com.tqyan.model.enums;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * @description 会话内容类型
 * <p> <功能详细描述> </p>
 *
 * @author 陈晨
 * @date 2023/4/11 17:51
 */
@Getter
@AllArgsConstructor
public enum ChatContentTypeEnum {

    TEXT(0, "文本"),
    PICTURE(1, "图片"),
    ;

    private final int value;
    private final String desc;

    public static ChatContentTypeEnum get(Integer value) {
        if (null == value) {
            return null;
        }
        return Arrays.stream(ChatContentTypeEnum.values())
                .filter(e -> e.value == value).findFirst().orElse(null);
    }

    public static ChatContentTypeEnum getByDesc(String desc) {
        if (StringUtils.isBlank(desc)) {
            return null;
        }
        return Arrays.stream(ChatContentTypeEnum.values())
                .filter(e -> e.desc.equals(desc)).findFirst().orElse(null);
    }

    public static Integer getValueByDesc(String desc) {
        ChatContentTypeEnum getEnum = Arrays.stream(ChatContentTypeEnum.values())
                .filter(e -> e.desc.equals(desc)).findFirst().orElse(null);
        if (null == getEnum) {
            return null;
        }
        return getEnum.getValue();
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }

}
